package com.yakumosakura.yakumoblade.event;
import com.yakumosakura.yakumoblade.utils.RandomUtil;
import com.yakumosakura.yakumoblade.registry.ItemRegistry;
import com.yakumosakura.yakumoblade.registry.slashblade.YASpecialEffectsRegistry;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class StarSoulEvent {
    @SubscribeEvent
    public static void hitBladeShelf(SlashBladeEvent.BladeStandAttackEvent event){
        if (event.getDamageSource().getEntity() instanceof Player player){
            if (player.getMainHandItem().getItem() == ItemRegistry.Star_Soul_Crystal.get()){
                event.setCanceled(true);
                ISlashBladeState slashBladeState = event.getSlashBladeState();


                  if (RandomUtil.randomnum(100)<=5
                          &&!slashBladeState.hasSpecialEffect(YASpecialEffectsRegistry.STAR_SOUL.getId())){
                      slashBladeState.addSpecialEffect(YASpecialEffectsRegistry.STAR_SOUL.getId());

                  }

                slashBladeState.setKillCount(slashBladeState.getKillCount()+200);
                slashBladeState.setProudSoulCount(slashBladeState.getProudSoulCount()+600);
                slashBladeState.setRefine(slashBladeState.getRefine()+1);
                slashBladeState.setMaxDamage(slashBladeState.getMaxDamage()+2);
                player.getMainHandItem().shrink(1);


            }
        }
    }
}
